package com.pospi.xstore.util;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.ListAdapter;
import android.widget.ListView;

/**
 * 常量
 */
public class Constant {

    public final static String VIP_PHONE ="手机号";
    public final static String VIP_NUMBER = "会员号";
    public final static String VIP_NAME = "姓名";
    public final static String VIP_SCAN = "扫一扫";

    public final static String USER_ID = "user_id";
    public final static String SYS_ID = "sys_id";


    /**
     * 订单类型的参数设置
     */
    public final static int ORDERTYPE_SALE = 1111;//正常销售模式
    public final static int ORDERTYPE_REFUND = 2222;//退货的模式
    public final static int ORDERTYPE_GD = 3333;//挂单的模式
    public final static int ORDERTYPE_LD = 4444;//落单的模式


    public final static int YES = 250;//已经完成的订单
    public final static int NO = 251;//未完成的订单


    public final static int hasReturnGoods_Yes = 112;//退过货
    public final static int hasReturnGoods_No = 113;//没有过退货

    public final static String MODEL_LAKALA = "V8";

    /**
     * 现金
     */
    public final static int PAYMENT_CASH = 1;
    public final static String PAYMENT_CASH_String = "现金";
    /**
     * 银行卡
     */
    public final static int PAYMENT_BANK_CARD = 2;
    public final static String PAYMENT_BANK_CARD_String = "银行卡";
    /**
     * 微信
     */
    public final static int PAYMENT_WEIXIN = 3;
    public final static String PAYMENT_WEIXIN_String = "微信";
    /**
     * 支付宝
     */
    public final static int PAYMENT_ALIPAY = 4;
    public final static String PAYMENT_ALIPAY_String = "支付宝";
    /**
     * 积分
     */
    public final static int PAYMENT_INTEGAL = 5;
    public final static String PAYMENT_INTEGAL_String = "积分";
    /**
     * 优惠券
     * */
    public final static int PAYMENT_OTHER = 6;
    public final static String PAYMENT_OTHER_String = "优惠券";


    public static final String STORE_ID = "store_id";
    public static final String STORE_NAME = "store_name";
    public static final String STORE_LIST = "store_list";
    public static final String SUP_LIST = "sup_list";
    public static final String CUS_LIST = "cus_list";
    public static final String BILL_TYPE_CGDD = "201";//采购订单
    public static final String BILL_TYPE_CGRK = "101";//采购入库
    public static final String BILL_TYPE_CGTC = "102";//采购退厂

    public static final String BILL_TYPE_XSDD = "205";//销售订单
    public static final String BILL_TYPE_XSCK = "105";//销售订单
    public static final String BILL_TYPE_XSTH = "106";//销售订单


    public static final String BILL_MODE_CGDD = "bill.mbillcgdd";//采购订单
    public static final String BILL_MODE_CGRK = "bill.mbillcgrk";//采购入库
    public static final String BILL_MODE_CGTC = "bill.mbillcgrk";//采购退厂

    public static final String PRO_SINGLE_REDUCE = "100";//单品促销价
    public static final String PRO_SINGLE_DISCOUNT = "101";//单品促销价
    public static final String PRO_N_REDUCE = "103";//第n件优惠

    public static final String PRO_ZP = "102";//赠品

    public static final int REQUEST_CGDD = 11;
    public static final int REQUEST_CGRK = 12;
    public static final int REQUEST_CGTC = 13;

    public static final int RESULT_CGDD = 14;
    public static final int RESULT_CGRK = 15;
    public static final int RESULT_CGTC = 16;
    public static final int YHQ = 20;
    public static final String UP_NO = "0";
    public static final String UP_OK = "1";
    public static final String COUNT_NAME = "COUNT_NAME";
    public static final String COUNT_QYH = "count_qyh";
    public static final String CUSTOMER = "customer";
    public static final String CUSTOMER_name = "customkername";

    public static final String BILL_TYPE_WSH = "1";
    public static final String BILL_TYPE_FHSH = "2";
    public static final String BILL_TYPE_SHSH = "3";
    public static final String BILL_TYPE_ZF = "4";


    public static int getScreemHeight(Context context) {


        WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);

        int height = wm.getDefaultDisplay().getHeight();
        return height;
    }

    /**
     * 得到屏幕宽度
     */
    public static int getScreemWidth(Context context) {

        WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);

        return wm.getDefaultDisplay().getWidth();
    }

    /**
     * 根据手机的分辨率从 dp 的单位 转成为 px(像素)
     */
    public static int dip2px(Context context, float dpValue) {
        final float scale = context.getResources().getDisplayMetrics().density;
        return (int) (dpValue * scale + 0.5f);
    }

    public static void fixListViewHeight(ListView listView) {
        // 如果没有设置数据适配器，则ListView没有子项，返回。
        ListAdapter listAdapter = listView.getAdapter();
        int totalHeight = 0;
        if (listAdapter == null) {
            return;
        }

        for (int i = 0; i < listAdapter.getCount(); i++) {
            View listViewItem = listAdapter.getView(i, null, listView);
            // 计算子项View 的宽高
            listViewItem.measure(0, 0);
            // 计算所有子项的高度和
            totalHeight += listViewItem.getMeasuredHeight();
        }
        ViewGroup.LayoutParams params = listView.getLayoutParams();
        // listView.getDividerHeight()获取子项间分隔符的高度
        // params.height设置ListView完全显示需要的高度
        params.height = totalHeight + (listView.getDividerHeight() * (listAdapter.getCount() - 1));
        listView.setLayoutParams(params);
    }
}
